import React from 'react';
import {BrowserRouter as Router,Route,Switch,Redirect} from 'react-router-dom';

import Major from './Major'
import {useSelector,useDispatch,connect} from 'react-redux'
import Login from './routes/Login'




const ContentMajor = () => {
  const login = useSelector(state=> state.login.islogin)
  const PrivateRoute = ({component:Com,...rest}) => {
    return <Route {...rest} render={({location}) => {
        const userInfo = login;
        if(userInfo){
            return Com
        }else{
            //从哪来到哪去
            return <Redirect to={
                {
                    pathname:'/login',
                    state:location
                }
            }/>
        }
    }
    }/>
}


  return (
    <div>
      <Switch>
        <PrivateRoute exact path="/" component={<Major prop='user'/>}/>
        <PrivateRoute path="/city/citycul" component={<Major prop='culture'/>}/>
        <PrivateRoute path="/city/interest" component={<Major prop='interest'/>}/>
        <PrivateRoute path="/city/enviro" component={<Major prop='enviro'/>}/>
        <PrivateRoute path="/city/food" component={<Major prop='food'/>}/>
        <PrivateRoute path="/city/hotel" component={<Major prop='hotel'/>}/>
        {/* <PrivateRoute path="/post" component={<Major prop='post'/>}/> */}
        <PrivateRoute path="/system" component={<Major prop='system'/>}/>
        <Route path="/login" component={Login} />
    </Switch>
    </div>
    
      
    
      
  )
}

export default connect()(ContentMajor);
